import {request} from "@umijs/max";
import {PageParam} from "@/services/common";
import {covertTableData} from "@/utils/tableUtil";

export interface CustomerChannelVO {
  /**
   * 渠道id
   */
  id: string;
  /**
   * 渠道名
   */
  channelName: string;
  color: string;
}

export interface CustomerChannelQueryDTO extends PageParam {
  /**
   * 渠道id
   */
  id?: string;
  /**
   * 渠道名
   */
  channelName?: string;
}

export interface CustomerChannelUpdateDTO {
  /**
   * 渠道id
   */
  id?: string;
  /**
   * 渠道名
   */
  channelName?: string;
}

export const getCustomerChannelById = async (id: string) => {
  return request<CustomerChannelVO>(`/api/customerChannel?id=${id}`, {method: 'GET'})
}

export const getCustomerChannelList = async (params?: CustomerChannelQueryDTO) => {
  return request<CustomerChannelVO[]>(`/api/customerChannel/list`, {method: 'GET', params})
}

export const getCustomerChannelPage = async (params: CustomerChannelQueryDTO) => {
  let response = await request<Array<CustomerChannelVO>>(`/api/customerChannel/page`, {method: 'GET', params})
  return covertTableData(response)
}

export const updateCustomerChannel = async (customerChannelUpdateDTO: CustomerChannelUpdateDTO) => {
  return request<CustomerChannelVO>(`/api/customerChannel/update`, {
    method: 'POST',
    data: customerChannelUpdateDTO
  })
}

export const saveCustomerChannel = async (customerChannelUpdateDTO: CustomerChannelUpdateDTO) => {
  return request<CustomerChannelVO>(`/api/customerChannel/save`, {method: 'POST', data: customerChannelUpdateDTO})
}

export const removeCustomerChannel = async (id: string) => {
  return request<boolean>(`/api/customerChannel/remove?id=${id}`, {method: 'POST'})
}
